import 'dart:math';

import 'package:flutter/material.dart';

class DynamicShapeBorderContainer extends StatelessWidget {
  final Widget child;
  final bool showBorder;
  final Color borderColor;
  final double width;
  final double height;
  static const double _minSize = 33;

  const DynamicShapeBorderContainer({
    super.key,
    required this.child,
    this.showBorder = true,
    this.borderColor = Colors.lightGreenAccent,
    this.width = _minSize, // 默认宽高为 33
    this.height = _minSize,
  });

  @override
  Widget build(BuildContext context) {
    // 判断是否为正方形
    final isSquare = (width - height).abs() < 0.1;

    // 动态圆角半径（仅当非正方形时生效）
    final cornerRadius = isSquare
        ? 0.0
        : (min(width, height) / 4);

    return Container(
      width: max(_minSize, width), // 父容器宽高最小为 33
      height: max(_minSize, height),
      alignment: Alignment.center,
      decoration: BoxDecoration(
        color: Colors.transparent,
        border: showBorder
            ? Border.all(
                color: borderColor,
                width: 2,
              )
            : null,
        shape: isSquare ? BoxShape.circle : BoxShape.rectangle,
        borderRadius: isSquare
            ? null
            : BorderRadius.circular(cornerRadius),
      ),
      child: SizedBox(
        width: width - 20, 
        height: height - 20,
        child: child,
      ),
    );
  }
}